package com.tungse.study.itreator_mode;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/**
 * 读取文件中的多行内容， 按行数据转为java对象集
 */
public class MainOne {
    public static void main(String[] args) throws IOException {
        List<UserOne> userOnes = new ArrayList<>();
        extracted((user)->{
            userOnes.add(user);
            System.out.println(user);
        });
    }

    private static void extracted(Consumer<UserOne> userOneConsumer) throws IOException {

        List<String> strings = Files.readAllLines(new File("E:\\StudyProjectWorkspace\\idea\\study\\design_mode\\itreator_demo\\src\\main\\java\\com\\tungse\\study\\demo.user").toPath());
        for (String s : strings) {
            String substring = s.substring(1, s.length() - 1);
            String[] split = substring.split(",");
            String name = split[0];
            int age = Integer.parseInt(split[1]);
            UserOne userOne = new UserOne(name, age);

            userOneConsumer.accept(userOne);
        }
    }
}
